package org.climber.controller;

import org.climber.pojo.Book;
import org.climber.services.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;

import java.util.List;

@Controller("bookController")
public class BookController {
    @Autowired
    @Qualifier("bookService")
    BookService bookService;

    public String test(){
        String message="over";
//        try{
            bookService.update("delete from book",null);
            bookService.update("insert into book values(?,?,?)",new Object[]{1,"b6","aucc"});
            bookService.update("insert into book values(?,?,?)",new Object[]{1,"b6","aucc2"});
//        }catch (Exception e){
//            message="rollback";
//        }
        return message;
    }

    public void find(){
        List<Book> query = bookService.query("select * from book", null);
        query.forEach(
                el-> System.out.println(((Book)el).toString())
        );
    }
}
